home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / basic / iqb9104.zip / UNSIGNED.BAS < prev   
BASIC Source File  |  1991-03-21  |  2KB  |  103 lines

  1. ' UNSIGNED.BAS
  2. '
  3. DECLARE FUNCTION usiADD% (A%, B%)
  4. DECLARE FUNCTION usiSUB% (A%, B%)
  5. DECLARE FUNCTION usiIDIV% (A%, B%)
  6. DECLARE FUNCTION usiMOD% (A%, B%)
  7. DECLARE FUNCTION usiMUL% (A%, B%)
  8. DECLARE FUNCTION usiLET% (A&)
  9. DECLARE FUNCTION usiVAL& (A%)
  10.  
  11. ' Add two unsigned integers
  12. X% = usiLET%(47500)
  13. Y% = usiLET%(10250)
  14. Z% = usiADD%(X%, Y%)
  15. PRINT usiVAL&(Z%)
  16.  
  17. ' Subtract two unsigned integers
  18. X% = usiLET%(64486)
  19. Y% = usiLET%(32100)
  20. Z% = usiSUB%(X%, Y%)
  21. PRINT usiVAL&(Z%)
  22.  
  23. ' Split an unsigned integer into bytes
  24. AX% = &HE0F0
  25. AXHi% = usiIDIV%(AX%, 256)
  26. AXLow% = usiMOD%(AX%, 256)
  27. PRINT HEX$(AX%), HEX$(AXHi%), HEX$(AXLow%)
  28.  
  29. ' Combine two bytes into an unsigned integer
  30. A% = usiLET%(&H81)
  31. B% = usiLET%(&H7F)
  32. C% = usiMUL%(A%, 256) OR B%
  33. PRINT HEX$(C%)
  34.  
  35. ' Assign an otherwise negative value
  36. ' to an unsigned integer & display it
  37. A% = usiLET%(&H8002)
  38. PRINT usiVAL&(A%)
  39.  
  40. ' Compare two unsigned integers
  41. A% = usiLET%(45000)
  42. B% = usiLET%(32000)
  43. IF usiVAL&(A%) > usiVAL&(B%) THEN PRINT "A% > B%"
  44.  
  45. ' Function to add two unsigned integers
  46.  
  47. FUNCTION usiADD% (A%, B%) STATIC
  48. tempA& = A% - 65536 * (A% < 0)
  49. tempB& = B% - 65536 * (B% < 0)
  50. sum& = tempA& + tempB&
  51. usiADD% = sum& + 65536 * (sum& > 32767)
  52. END FUNCTION
  53.  
  54. ' Function to do unsigned integer division
  55.  
  56. FUNCTION usiIDIV% (A%, B%) STATIC
  57. tempA& = A% - 65536 * (A% < 0)
  58. tempB& = B% - 65536 * (B% < 0)
  59. div& = tempA& \ tempB&
  60. usiIDIV% = div& + 65536 * (div& > 32767)
  61. END FUNCTION
  62.  
  63. ' Function to assign an unsigned value to an integer
  64.  
  65. FUNCTION usiLET% (A&) STATIC
  66. usiLET% = A& + 65536 * (A& > 32767)
  67. END FUNCTION
  68.  
  69. ' Function to perform unsigned modular arithmetic
  70.  
  71. FUNCTION usiMOD% (A%, B%) STATIC
  72. tempA& = A% - 65536 * (A% < 0)
  73. tempB& = B% - 65536 * (B% < 0)
  74. rmnd& = tempA& MOD tempB&
  75. usiMOD% = rmnd& + 65536 * (rmnd& > 32767)
  76. END FUNCTION
  77.  
  78. ' Function to multiply two unsigned integers
  79.  
  80. FUNCTION usiMUL% (A%, B%) STATIC
  81. tempA& = A% - 65536 * (A% < 0)
  82. tempB& = B% - 65536 * (B% < 0)
  83. prod& = tempA& * tempB&
  84. usiMUL% = prod& + 65536 * (prod& > 32767)
  85. END FUNCTION
  86.  
  87. ' Function to subtract two unsigned integers
  88.  
  89. FUNCTION usiSUB% (A%, B%) STATIC
  90. tempA& = A% - 65536 * (A% < 0)
  91. tempB& = B% - 65536 * (B% < 0)
  92. dif& = tempA& - tempB&
  93. usiSUB% = dif& + 65536 * (dif& > 32767)
  94. END FUNCTION
  95.  
  96. ' Function to return the value of an unsigned integer
  97. ' as a long
  98.  
  99. FUNCTION usiVAL& (A%) STATIC
  100. usiVAL& = A% - 65536 * (A% < 0)
  101. END FUNCTION
  102.  
  103.